package com.wanmait.hr.util;

public class Pager
{
    private int pageNo;
    private int pageSize;
    private int dataCount;
    public int getPageNo() {

        if(pageNo>this.getPageCount()) {
            return this.getPageCount();
        }
        if(pageNo<1) {
            return 1;
        }
        return pageNo;
    }
    public void setPageNo(int pageNo) {
        try {
            this.pageNo = pageNo;
        } catch (Exception e) {

            this.pageNo = 1;
        }
    }
    public int getPageSize() {
        if(pageSize<1) {
            pageSize=10;
        }
        return pageSize;
    }
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
    public int getDataCount() {
        return dataCount;
    }
    public void setDataCount(int dataCount) {
        this.dataCount = dataCount;
    }
    public int getPageCount() {
        return (dataCount-1)/this.getPageSize()+1;
    }

    public int getPrevPageNo()
    {
        if(this.getPageNo()>1) {
            return this.getPageNo()-1;
        }
        return 1;
    }
    public int getNextPageNo()
    {
        if(this.getPageNo()<this.getPageCount()) {
            return this.getPageNo()+1;
        }
        return this.getPageCount();
    }
    public int getCurrentPageSize()
    {
        return (getPageNo()-1)*this.getPageSize();
    }
    public boolean getFrontPoints() {
        return this.getPageNo() > 5 && this.getPageNo() <= this.getPageCount();
    }
    public boolean getBackPoints() {
        return this.getPageNo() > 0 && this.getPageNo() < this.getPageCount() - 2 && this.getPageCount() > 5;
    }
    public int [] getPageArray() {

        if(this.getPageNo() > 0 && this.getPageNo() <= 3 ) {

            switch (this.getPageCount()) {
                case 1:
                    return null;
                case 2:
                    return null;
                case 3:
                    int [] pageArray3 = {3};
                    return pageArray3;
                case 4:
                    int [] pageArray4 = {3,4};
                    return pageArray4;
                default:
                    int [] pageArray5 = {3,4,5};
                    return pageArray5;
            }
        }
        else if(this.getPageNo() > 3 && this.getPageCount() <= 5) {

            switch (this.getPageCount()) {
                case 4:
                    int [] pageArray1 = {3,4};
                    return pageArray1;
                case 5:
                    int [] pageArray2 = {3,4,5};
                    return pageArray2;
            }
        }
        else if(this.getPageCount() >5 && this.getPageNo() > this.getPageCount()-2) {
            if(this.getPageNo()==this.getPageCount()-1) {
                int [] pageArray = {this.getPageCount()-4,this.getPageCount()-3,this.getPageCount()-2,this.getPageCount()-1,this.getPageCount()};
                return pageArray;
            }
            if(this.getPageNo()==this.getPageCount()) {
                int [] pageArray = {this.getPageCount()-4,this.getPageCount()-3,this.getPageCount()-2,this.getPageCount()-1,this.getPageCount()};
                return pageArray;
            }


            int [] pageArray = {this.getPageNo()-2,this.getPageNo()-1,this.getPageNo(),this.getPageNo()+1,this.getPageNo()+2};
            return pageArray;
        }
        else {
            if(this.getPageNo()==4) {
                int [] pageArray = {this.getPageNo()-1,this.getPageNo(),this.getPageNo()+1,this.getPageNo()+2};
                return pageArray;
            }
            int [] pageArray = {this.getPageNo()-2,this.getPageNo()-1,this.getPageNo(),this.getPageNo()+1,this.getPageNo()+2};
            return pageArray;
        }
        return null;
    }
}
